package com.zhiziai.aiproxy.config;

import com.alibaba.fastjson.JSONObject;
import com.zhiziai.aiproxy.dto.MidJourneyTask;
import com.zhiziai.aiproxy.service.MidjourneyServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

@Slf4j
public class MJEventReceiver {

    public void receiveMessage(String message) {
        log.info("Received <" + message + ">");
        if(StringUtils.isNotEmpty(message)){
            MidJourneyTask midJourneyTask = JSONObject.parseObject(message, MidJourneyTask.class);
            String taskId = midJourneyTask.getId();
            MidjourneyServiceImpl.listenMidTaskMap.put(taskId+"_"+midJourneyTask.getState(),midJourneyTask);
            MidjourneyServiceImpl.lockMap.get(taskId+"_"+midJourneyTask.getState()).countDown();
        }
    }
}
